package com.ejuornal.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ejuornal.bean.Page;
import com.ejuornal.bean.Subscribe;
import com.ejuornal.dao.SubscribeDao;
import com.ejuornal.service.SubscribeService;

@Component("subscribeService")
public class SubscribeServiceImpl implements SubscribeService {
	private SubscribeDao subscribeDao;

	public void add(Subscribe subscribe) {
		String sql = "INSERT INTO t_subscribe VALUES(?, ?, ?)";
		subscribeDao.add(sql, new Object[] { 
									null, 
									subscribe.getUserId(),
									subscribe.getPeriodicalId() });
	}

	public void delete(int... subscribeIds) {
		String sql = "DELETE FROM t_subscribe WHERE subscribeId = ?";
		subscribeDao.batchDelete(sql, subscribeIds);
	}

	public Subscribe findBySubscribeId(int subscribeId) {
		return subscribeDao.findById(subscribeId);
	}

	public Page<Subscribe> findByUserId(int current_record, String url, int userId) {
		String hsql = "WHERE userId = ?";
		return subscribeDao.find(current_record, url, hsql, new Object[]{ userId });
	}
	@Override
	public void cancelSubscribe(int periodicalId, int userId) {
		subscribeDao.cancelSubscribe(periodicalId, userId);
	}

	public List<String> findByListPeriodicalId(int periodicalId) {
		return subscribeDao.findByListPeriodicalId(periodicalId);
	}

	@Override
	public int isSubscribe(int userId, int periodicalId) {
		return subscribeDao.isSubscribe(userId, periodicalId);
	}

	public SubscribeDao getSubscribeDao() {
		return subscribeDao;
	}

	@Resource(name = "subscribeDao")
	public void setSubscribeDao(SubscribeDao subscribeDao) {
		this.subscribeDao = subscribeDao;
	}

	
}
